package com.lagou.edu.utils;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author meng.han
 * @date 2021-09-14
 */
@Component
@Aspect
public class LogUtil {

    @Pointcut("execution(* com.lagou.edu.service.*.*(..))")
    public void pointcut() {

    }

    @Before("pointcut()")
    public void before() {
        System.out.println("前置方法");
    }

    @After("pointcut()")
    public void after() {
        System.out.println("后置方法");
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        Object result;
        System.out.println("环绕方法前");
        result = pjp.proceed();
        System.out.println("环绕方法后");
        return result;
    }

    @AfterReturning(value = "pointcut()", returning = "obj")
    public void afterReturning(Object obj) {
        System.out.println("返回结果方法" + obj);
    }

    @AfterThrowing(value = "pointcut()", throwing = "e")
    public void exception(Throwable e) {
        System.out.println("异常方法" + e.getMessage());
    }
}
